package com.example.italkapp2.utils;

import android.content.Context;
import android.content.SharedPreferences;

import com.example.italkapp2.controller.IMApplication;

//保存数据
//获取数据
public class SpUtils {

    public static final String IS_NEW_INVITE = "is_new_invite";//新的邀请标记(小红点)
    private static SpUtils instance=new SpUtils();
    private static SharedPreferences mSp;


    private SpUtils(){

    }

    //单例工具类
    public static SpUtils getInstance(){

        if(mSp==null){
            mSp=IMApplication.getGlobalApplication().getSharedPreferences("im", Context.MODE_PRIVATE);
        }

        return instance;
    }

    //保存数据
    public void save(String key,Object value){

        if(value instanceof String){
            mSp.edit().putString(key,(String)value).commit();
        }else if(value instanceof Boolean){
            mSp.edit().putBoolean(key,(Boolean)value).commit();
        }else if(value instanceof Integer){
        mSp.edit().putInt(key,(Integer) value).commit();
        }
    }

    //获取数据
    public String getString(String key,String defValue){
        return mSp.getString(key, defValue);
    }
    public Boolean getBoolean(String key,Boolean defValue){
        return mSp.getBoolean(key, defValue);
    }
    public int getInteger(String key,int defValue){
        return mSp.getInt(key, defValue);
    }

}
